package spike.s003.sqlflow.entity;

import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * Created by ylyang on 04/04/2017.
 */
public class StudentCourseEntity {
    private String studentID;
    private String courseID;
    private Integer score;
    private Date createTime;
    private CourseEntity courseEntity;

    public String getStudentID() {
        return studentID;
    }

    public void setStudentID(String studentID) {
        this.studentID = studentID;
    }

    public String getCourseID() {
        return courseID;
    }

    public void setCourseID(String courseID) {
        this.courseID = courseID;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public CourseEntity getCourseEntity() {
        return courseEntity;
    }

    public void setCourseEntity(CourseEntity courseEntity) {
        this.courseEntity = courseEntity;
    }

    public static class BeanRowMapper {
        private static final BeanPropertyRowMapper<StudentCourseEntity> MAPPER = BeanPropertyRowMapper.newInstance(StudentCourseEntity.class);

        public static StudentCourseEntity mapRow(ResultSet rs) throws SQLException {
            String s = rs.getString("student_ID");

            StudentCourseEntity studentCourseEntity = MAPPER.mapRow(rs, rs.getRow());
            studentCourseEntity.setStudentID(s);
            studentCourseEntity.setCourseID(rs.getString("course_ID"));
            studentCourseEntity.setScore(rs.getInt("score"));
            studentCourseEntity.setCreateTime(rs.getDate("create_time"));
            return studentCourseEntity;
        }
    }

    @Override
    public String toString() {
        return "StudentCourseEntity{" +
                "studentID='" + studentID + '\'' +
                ", courseID='" + courseID + '\'' +
                ", score=" + score +
                ", createTime=" + createTime +
                ", courseEntity=" + courseEntity +
                '}';
    }
}
